<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xi="http://www.w3.org/2001/XInclude" version="1.0">
  <xsl:include href="domains.xsl"/>
  <xsl:include href="dates.xsl"/>


  <xsl:template match="@align">
    <xsl:attribute name="align">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@valign">
    <xsl:attribute name="valign">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@alt">
    <xsl:attribute name="title">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@chunk">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@collection-type">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@copy-to">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@format">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@frame">
    <!-- http://www.w3.org/TR/html401/struct/tables.html#adef-frame -->
    <xsl:attribute name="frame">
      <xsl:choose>
        <xsl:when test="'top' = .">above</xsl:when>
        <xsl:when test="'bottom' = .">below</xsl:when>
        <xsl:when test="'topbot' = .">hsides</xsl:when>
        <xsl:when test="'all' = .">box</xsl:when>
        <xsl:when test="'sides' = .">border</xsl:when>
        <xsl:when test="'none' = .">void</xsl:when>
        <xsl:otherwise>void</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@height">
    <xsl:attribute name="height">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@href">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="image/@href | hazardsymbol/@href">
    <xsl:attribute name="src">
      <xsl:text>../images/</xsl:text>
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="@keys">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@linking">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@navtitle">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@pgwide">
    <xsl:if test="'1' = .">
      <xsl:attribute name="width">100%</xsl:attribute>
    </xsl:if>
  </xsl:template>
  <xsl:template match="@print">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@query">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@search">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@state">
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="@toc">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <xsl:template match="@value">
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="@width">
    <xsl:attribute name="width">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' map/map ')]">
    <div class="map">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/mapref ')]">
    <a class="mapref">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/topicsetref ')]">
    <a class="topicsetref">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/topicset ')]">
    <div class="topicset">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/topichead ')]">
    <span class="topichead">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/keydef ')]">
    <span class="keydef">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/anchor ')]">
    <a class="anchor">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/navref ')]">
    <a class="navref">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/reltable ')]">
    <div class="reltable">
      <table>
        <xsl:apply-templates select="node()"/>
      </table>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/relheader ')]">
    <thead>
      <tr class="relheader">
        <xsl:apply-templates select="node()"/>
      </tr>
    </thead>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/relcolspec ')]">
    <th class="relcolspec">
      <span class="relcolspec-type">
        <xsl:apply-templates select="@type"/>
      </span>
      <xsl:apply-templates select="node()"/>
    </th>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/relrow ')]">
    <tr class="relrow">
      <xsl:apply-templates select="node()"/>
    </tr>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/relcell ')]">
    <td class="relcell">
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Cell&gt;</span>
      </xsl:if>
      <xsl:apply-templates select="node()"/>
    </td>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' mapgroup-d/anchorref ')]">
    <a class="anchorref">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/topicmeta ')]">
    <div class="map-topicmeta">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/linktext ')]">
    <span class="linktext">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/searchtitle ')]">
    <h4 class="searchtitle">
      <xsl:apply-templates select="node()"/>
    </h4>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' map/shortdesc ')]">
    <div class="shortdesc">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/topic ')]">
    <div class="topic">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/titlealts ')]">
    <div class="titlealts">
      <xsl:apply-templates select="node()"/>
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Title Alternatives&gt;</span>
      </xsl:if>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/searchtitle ')]">
    <h4 class="searchtitle">
      <xsl:apply-templates select="node()"/>
    </h4>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/navtitle ')]">
    <h4 class="navtitle">
      <xsl:apply-templates select="node()"/>
    </h4>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/desc ')]">
    <div class="desc">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/shortdesc ')]">
    <div class="shortdesc">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/prolog ')]">
    <div class="prolog">
      <xsl:apply-templates select="node()"/>
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Prolog&gt;</span>
      </xsl:if>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/body ')]">
    <div class="body">
      <xsl:apply-templates select="node()"/>
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Body&gt;</span>
      </xsl:if>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/bodydiv ')]">
    <div class="bodydiv">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/p ')]">
    <div class="p">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/prodinfo ')]">
    <div class="prodinfo">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/publisher ')]">
    <div class="publisher">
      <span class="xopus-visualisation-label">Publisher: </span>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/permissions ')]">
    <div class="permissions">
      <span class="xopus-visualisation-label">Permissions: </span>
      <xsl:value-of select="@view"/>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/ul ')]">
    <ul class="ul">
      <xsl:apply-templates select="node()"/>
    </ul>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/ol ')]">
    <ol class="ol">
      <xsl:if test="@outputclass">
        <xsl:attribute name="style">list-style-type:<xsl:value-of select="@outputclass"/></xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node()"/>
    </ol>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/li ')]">
    <li class="li">
      <xsl:apply-templates select="node()"/>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/itemgroup ')]">
    <div class="itemgroup">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/sl ')]">
    <ul class="sl">
      <xsl:apply-templates select="node()"/>
    </ul>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/sli ')]">
    <li class="sli">
      <xsl:apply-templates select="node()"/>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dl ')]">
    <dl class="dl">
      <xsl:apply-templates select="node()"/>
    </dl>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dlhead ')]">
    <div class="dlhead">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dlentry ')]">
    <div class="dlentry">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dt ')]">
    <dt class="dt">
      <xsl:apply-templates select="node()"/>
    </dt>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dd ')]">
    <dd class="dd">
      <xsl:apply-templates select="node()"/>
    </dd>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/dthd ')]">
    <dt class="dthd">
      <xsl:apply-templates select="node()"/>
    </dt>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/ddhd ')]">
    <dd class="ddhd">
      <xsl:apply-templates select="node()"/>
    </dd>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/lines ')]">
    <pre class="lines">
      <xsl:apply-templates select="@xml:space"/>
      <xsl:apply-templates select="node()"/>
    </pre>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/ph ')]">
    <xsl:variable name="types">
      <xsl:value-of select="normalize-space(translate(translate(@class, '-+', ''), '/', '-'))"/>
    </xsl:variable>
    <span class="ph types {$types}">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/boolean ')]">
    <span class="boolean xopus-visualisation-spec-deprecated">
      <xsl:apply-templates select="@state | node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/example ')]">
    <div class="example">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/state ')]">
    <span class="state" title="{@name}">
      <!-- FIXME need more explanation / use cases -->
      <xsl:value-of select="@name"/>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="@value"/>
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/tm ')]">
    <span class="tm">
      <xsl:apply-templates select="node()"/>
      <!-- FIXME what default rendering?  -->
      <xsl:if test="@tmtype = 'reg'">&#x00AE;</xsl:if><!-- registered trademark -->
      <xsl:if test="@tmtype = 'tm'">&#x2122;</xsl:if><!-- trademark -->
      <xsl:if test="@tmtype = 'sm'">&#x2121;</xsl:if><!-- service mark -->
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/author ')]">
    <div class="author" title="{@type}">
      <span class="xopus-visualisation-label">Author: </span>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/source ')]">
    <div class="source">
      <span class="xopus-visualisation-label">Source: </span>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/audience ')]">
    <div class="audience">
      <span class="xopus-visualisation-label">Audience: </span><!-- FIXME get attrs -->
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/category ')]">
    <div class="category">
      <span class="xopus-visualisation-label">Category: </span><!-- FIXME collapse categories (and audiences) -->
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/critdates ')]">
    <div class="critdates">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/created ')]">
    <div class="created">
      <span class="xopus-visualisation-label">Created: </span>
      <xsl:apply-templates select="@date"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/revised ')]">
    <div class="revised">
      <span  class="xopus-visualisation-label">Revised: </span>
      <xsl:apply-templates select="@modified"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/metadata ')]">
    <div class="metadata">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/othermeta ')]">
    <div class="othermeta">
      <span class="xopus-visualisation-label">
        <xsl:value-of select="@name"/>
        <xsl:text>: </xsl:text>
      </span>
      <xsl:value-of select="@content"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/keywords ')]">
    <div class="keywords">
      <span class="xopus-visualisation-label">Keywords: </span>
      <xsl:for-each select="*">
        <xsl:apply-templates select="."/>
        <xsl:if test="following-sibling::*">
          <xsl:text>, </xsl:text>
        </xsl:if>
      </xsl:for-each>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/keyword ')]">
    <xsl:variable name="types">
      <xsl:value-of select="normalize-space(translate(translate(@class, '-+', ''), '/', '-'))"/>
    </xsl:variable>
    <span class="keyword {$types}">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/text ')]">
    <span class="text">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/prodname ')]">
    <div class="prodname">
      <span class="xopus-visualisation-label">Product Name: </span>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/vrmlist ')]">
    <div class="vrmlist">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/vrm ')]">
    <div class="vrm"><!-- FIXME needs more work, ie placeholders -->
      <span class="xopus-visualisation-label">Product Version: </span>
      <xsl:value-of select="@version"/>
      <xsl:if test="@release != ''">.</xsl:if>
      <xsl:value-of select="@release"/>
      <xsl:if test="@modification != ''">.</xsl:if>
      <xsl:value-of select="@modification"/>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/resourceid ')]">
    <div class="resourceid">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>


  <xsl:template match="*[contains(@class, ' topic/related-links ')]">
    <ul class="related-links">
      <xsl:apply-templates select="node()"/>
    </ul>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/linklist ')]">
    <!-- FIXME test on classnames instead of element names -->
    <li class="linklist">
      <xsl:apply-templates select="title|desc"/>
      <ol>
        <xsl:apply-templates select="linklist | link"/>
      </ol>
      <xsl:apply-templates select="linkinfo"/>
    </li>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/link ')]">
    <li class="link">
      <a>
        <xsl:apply-templates select="@href"/>
        <xsl:apply-templates select="linktext"/>
        <xsl:if test="not(linktext)">
          <xsl:value-of select="string(@href)"/>
          <xsl:if test="not(@href)">
            <xsl:text>&lt;link&gt;</xsl:text>
          </xsl:if>
        </xsl:if>
      </a>
      <xsl:apply-templates select="desc"/>
    </li>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/linkpool ')]">
    <xsl:variable name="collection-type">
      <xsl:choose>
        <xsl:when test="@collection-type = 'unordered'">unordered</xsl:when>
        <xsl:when test="@collection-type = 'sequence'">sequence</xsl:when>
        <xsl:when test="@collection-type = 'choice'">choice</xsl:when>
        <xsl:when test="@collection-type = 'family'">family</xsl:when>
        <xsl:otherwise>unordered</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <li class="linkpool collection-type-{$collection-type}">
      <ul>
        <xsl:apply-templates select="node()"/>
      </ul>
    </li>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/linkinfo ')]">
    <div class="linkinfo">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/linktext ')]">
    <span class="linktext">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/pre ')]">
    <pre class="pre">
      <xsl:apply-templates select="node()"/>
    </pre>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/xref ')]">
    <a class="xref">
      <xsl:apply-templates select="@href"/>
      <xsl:apply-templates select="node()"/>
    </a>
    <span class="xopus-visualisation-href"> [<xsl:value-of select="@href"/>]</span>
    <!-- XXX location matters: when @href has its own template, the placeholders go haywire -->
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/note ')]">
    <div class="note">
      <xsl:apply-templates select="@type"/>
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/cite ')]">
    <cite class="cite">
      <xsl:apply-templates select="node()"/>
    </cite>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/abstract ')]">
    <div class="abstract">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/section ')]">
    <div class="section">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/sectiondiv ')]">
    <div class="sectiondiv">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  
  <xsl:template match="*[contains(@class, ' topic/image ')]">
    <span class="attr-placement-{@placement} attr-image-align-{@align} attr-scalefit-{@scalefit}">
      <img class="attr-scalefit-{@scalefit}">
        <xsl:apply-templates select="@href|@alt|@width|@height"/>
      </img>
      <xsl:apply-templates select="longdescref | alt"/>
    </span>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/alt ')]">
    <span class="alt">
      <span class="xopus-visualisation-label"> Alternate text: </span>
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  
  <xsl:template match="*[contains(@class, ' topic/longdescref ')]">
    <span class="longdescref">
      <span class="xopus-visualisation-label"> Long Description &lt;</span>
      <span><xsl:value-of select="@href"/></span>
      <xsl:text>&gt;</xsl:text>
    </span>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/fig ')]">
    <div class="topic-fig">
      <!-- FIXME do we need to place title AKA caption and description below ? -->
      <xsl:apply-templates select="title"/>
      <xsl:apply-templates select="desc"/>
      <div class="xopus-visualisation-frame attr-frame-{@frame}">
        <xsl:apply-templates select="node()[not(self::title | self::desc)]"/>
      </div>
      <xsl:if test="not(*)"><span class="dummy">&lt;Figure&gt;</span></xsl:if>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/figgroup ')]">
    <div class="figgroup">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/object ')]">
    <div class="object"><!-- FIXME do we support this? -->
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/param ')]">
    <div class="param">
      <xsl:apply-templates select="node()"/>
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Parameter&gt;</span>
      </xsl:if>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/foreign ')]">
    <div class="foreign">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/unknown ')]">
    <div class="unknown">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/data ')]">
    <span class="data">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/data-about ')]">
    <div class="data-about">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/term ')]">
    <span class="term">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/no-topic-nesting ')]">
    <div class="no-topic-nesting">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>


  <xsl:template match="*[contains(@class, ' topic/table ')]">
    <div class="topic-table">
      <table>
        <xsl:apply-templates select="@frame"/>
        <xsl:apply-templates select="@pgwide"/>

        <!-- http://www.w3.org/TR/html401/struct/tables.html#adef-rules -->
        <xsl:if test="@colsep or @rowsep">
          <xsl:attribute name="rules">
            <xsl:choose>
              <xsl:when test="@colsep='1' and @rowsep='1'">all</xsl:when>
              <xsl:when test="@colsep='1'">cols</xsl:when>
              <xsl:when test="@rowsep='1'">rows</xsl:when>
              <xsl:otherwise>none</xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
        </xsl:if>
        <xsl:apply-templates select="*[contains(@class, ' topic/title ') or contains(@class, ' topic/tgroup ')]"/>
      </table>
      <xsl:apply-templates select="desc"/>
    </div>
  </xsl:template>


  <xsl:template match="*[contains(@class, ' topic/tgroup ')]">
    <colgroup span="{@cols}">
      <xsl:apply-templates select="colspec"/>
    </colgroup>
    <xsl:apply-templates select="*[contains(@class, ' topic/thead ')]"/>
    <xsl:apply-templates select="*[contains(@class, ' topic/tbody ')]"/>
  </xsl:template>
    
  <xsl:template match="*[contains(@class, ' topic/colspec ')]">
    <col>
      <xsl:apply-templates select="@colwidth"/>
      <xsl:apply-templates/>
    </col>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/thead ')]">
    <thead class="thead">
      <xsl:apply-templates select="parent::*/@align"/>
      <xsl:apply-templates select="@valign"/>
      <xsl:apply-templates select="node()"/>
    </thead>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/tbody ')]">
    <tbody class="tbody">
      <xsl:apply-templates select="parent::*/@align"/>
      <xsl:apply-templates select="@valign"/>
      <xsl:apply-templates select="node()"/>
    </tbody>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/row ')]">
    <tr class="row">
      <xsl:apply-templates select="." mode="table-section-cellvalign"/>
      <xsl:apply-templates select="node()"/>
    </tr>
  </xsl:template>
  
  <xsl:template match="*[contains(@class, ' topic/entry ')]">
    <xsl:variable name="type">
      <xsl:choose>
        <!-- FIXME use xpath on the class and on not the element name-->
        <xsl:when test="contains(parent::*/parent::*/@class, ' topic/thead ') or (ancestor::table[1][@rowheader = 'firstcol'] and not(preceding-sibling::entry))">th</xsl:when>
        <xsl:otherwise>td</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$type}">
      <xsl:attribute name="class">entry</xsl:attribute>
      <xsl:apply-templates select="@morerows | @nameend | @valign | @align"/>
      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="*" mode="table-section-cellhalign">
    <xsl:if test="@align">
      <xsl:attribute name="align">
        <xsl:value-of select="@align"/>
      </xsl:attribute>
    </xsl:if>
  </xsl:template>

  <xsl:template match="*" mode="table-section-cellvalign">
    <xsl:if test="@valign">
      <xsl:attribute name="valign">
        <xsl:value-of select="@valign"/>
      </xsl:attribute>
    </xsl:if>
  </xsl:template>

  <xsl:template match="@nameend">
    <xsl:variable name="tgroup" select="ancestor::tgroup[1]"/>
    <xsl:variable name="startname" select="../@namest"/>
    <xsl:variable name="endname" select="."/>
    <xsl:variable name="endcol" select="$tgroup/colspec[@colname = $endname]"/>
    <xsl:variable name="startcol" select="$tgroup/colspec[@colname = $startname]"/>
    <xsl:attribute name="colspan">
      <xsl:value-of select="1 + count($endcol/preceding-sibling::colspec) - count($startcol/preceding-sibling::colspec)"/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="@morerows">
    <xsl:attribute name="rowspan">
      <xsl:value-of select="number(.) + 1"/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/simpletable ') and not(contains(@class, ' learning-d/lcMatchTable '))]">
    <div class="simpletable">
      <table>
        <xsl:apply-templates select="@frame"/>
        <xsl:apply-templates select="node()"/>
      </table>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/sthead ')and not(contains(@class, ' learning-d/lcMatchingHeader '))]">
    <tr class="sthead">
      <xsl:apply-templates select="node()"/>
    </tr>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/strow ')and not(contains(@class, ' learning-d/lcMatchingPair '))]">
    <tr class="strow">
      <xsl:apply-templates select="node()"/>
    </tr>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/stentry ') and not(contains(parent::*/@class, ' topic/sthead ')) and not(contains(@class, ' learning-d/'))]">
    <!-- Generate padding on reference/property tables -->
    <!-- TODO should we move this to a reference XSL? -->
    <xsl:if test="contains(@class, ' reference/propvalue ') and not(preceding-sibling::*)">
      <td class="stentry"/>
    </xsl:if>
    <xsl:if test="contains(@class, ' reference/propdesc ') and not(preceding-sibling::*)">
      <td class="stentry" colspan="2"/>
    </xsl:if>
    <xsl:if test="contains(@class, ' reference/propdesc ') and contains(preceding-sibling::*[1]/@class, ' reference/proptype ')">
      <td class="stentry"/>
    </xsl:if>
    <td class="stentry">
      <xsl:apply-templates select="node()"/>
    </td>
  </xsl:template>
  <xsl:template match="*[contains(parent::*/@class, ' topic/sthead ') and contains(@class, ' topic/stentry ')]">
    <!-- Generate padding on reference/property tables -->
    <!-- TODO should we move this to a reference XSL? -->
    <xsl:if test="contains(@class, ' reference/propvaluehd ') and not(preceding-sibling::*)">
      <td class="stentry"/>
    </xsl:if>
    <xsl:if test="contains(@class, ' reference/propdeschd ') and not(preceding-sibling::*)">
      <td class="stentry" colspan="2"/>
    </xsl:if>
    <xsl:if test="contains(@class, ' reference/propdeschd ') and contains(preceding-sibling::*[1]/@class, ' reference/proptypehd ')">
      <td class="stentry"/>
    </xsl:if>

    <th class="stentry">
      <xsl:apply-templates select="node()"/>
    </th>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' topic/indexterm ')]">
    <span class="indexterm">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/index-base ')]">
    <div class="index-base">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/indextermref ')]">
    <span class="indextermref">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/fn ')]">
    <div class="fn">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/featnum ')]">
    <div class="featnum">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/prognum ')]">
    <div class="prognum">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/platform ')]">
    <div class="platform">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/series ')]">
    <div class="series">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/brand ')]">
    <div class="brand">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/component ')]">
    <div class="component">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/task ')]">
    <div class="task">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/steps ')]">
    <ol class="steps">
      <xsl:apply-templates select="node()"/>
    </ol>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/steps-unordered ')]">
    <ul class="steps-unordered">
      <xsl:apply-templates select="node()"/>
    </ul>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/step ')]">
    <li class="step">
      <xsl:apply-templates select="node()"/>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/stepxmp ')]">
    <div class="stepxmp">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' task/tutorialinfo ')]">
    <div class="tutorialinfo">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' task/stepsection ')]">
    <div class="stepsection"><!-- XXX inherits from topic/li and is nested in a ol? -->
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' reference/refsyn ')]">
    <div class="refsyn">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' delay-d/exportanchors ')]">
    <div class="exportanchors">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/i ')]">
    <i class="i">
      <xsl:apply-templates select="node()"/>
    </i>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/b ')]">
    <b class="b">
      <xsl:apply-templates select="node()"/>
    </b>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/u ')]">
    <u class="u">
      <xsl:apply-templates select="node()"/>
    </u>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/sub ')]">
    <sub class="sub">
      <xsl:apply-templates select="node()"/>
    </sub>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/sup ')]">
    <sup class="sup">
      <xsl:apply-templates select="node()"/>
    </sup>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hi-d/tt ')]">
    <code class="tt">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/apiname ')]">
    <code class="prd-apiname">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>

  <xsl:template match="*[contains(@class, ' pr-d/synph ')]">
    <code class="synph">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/codeblock ')]">
    <pre class="prd-codeblock">
      <xsl:apply-templates select="node()"/>
    </pre>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/codeph ')]">
    <code class="codeph">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/kwd ')]">
    <code class="kwd">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/repsep ')]">
    <code class="repsep">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/sep ')]">
    <code class="sep">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/oper ')]">
    <code class="oper">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/var ')]">
    <code class="var">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' pr-d/delim ')]">
    <code class="delim">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' ui-d/screen ')]">
    <pre class="uid-screen">
      <xsl:apply-templates select="node()"/>
    </pre>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' ui-d/menucascade ')]">
    <span class="menucascade">
      <xsl:for-each select="node()">
        <xsl:apply-templates select="."/>
        <xsl:if test="following-sibling::*">
          <span class="xopus-ui-menucascade-connector"> &gt; </span>
        </xsl:if>
      </xsl:for-each>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' ut-d/imagemap ')]">
    <div class="imagemap">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' ut-d/area ')]">
    <div class="area">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/filepath ')]">
    <code class="filepath">
      <xsl:apply-templates select="node()"/>
    </code>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/msgblock ')]">
    <div class="swd-msgblock block-wrapper">
      <samp class="msgblock">
        <xsl:apply-templates select="node()"/>
      </samp>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/msgnum ')]">
    <samp class="msgnum">
      <xsl:apply-templates select="node()"/>
    </samp>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/varname ')]">
    <var class="varname">
      <xsl:apply-templates select="node()"/>
    </var>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/systemoutput ')]">
    <samp class="systemoutput">
      <xsl:apply-templates select="node()"/>
    </samp>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/userinput ')]">
    <kbd class="userinput">
      <xsl:apply-templates select="node()"/>
    </kbd>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/msgph ')]">
    <samp class="msgph">
      <xsl:apply-templates select="node()"/>
    </samp>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' sw-d/cmdname ')]">
    <var class="cmdname">
      <xsl:apply-templates select="node()"/>
    </var>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hazard-d/messagepanel ')]">
    <ul class="messagepanel">
      <xsl:apply-templates select="node()"/>
    </ul>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hazard-d/hazardstatement ')]">
    <div class="hazardstatement">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hazard-d/typeofhazard ')]">
    <li class="typeofhazard">
      <xsl:apply-templates select="node()"/>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hazard-d/howtoavoid ')]">
    <li class="howtoavoid">
      <xsl:apply-templates select="node()"/>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' hazard-d/consequence ')]">
    <li class="consequence">
      <xsl:apply-templates select="node()"/>
      <xsl:if test="text()='' or count(*) = 0">
        <span class="dummy">&lt;Consequence&gt;</span>
      </xsl:if>
    </li>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' indexing-d/index-see ')]">
    <div class="index-see">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' indexing-d/index-see-also ')]">
    <div class="index-see-also">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' indexing-d/index-sort-as ')]">
    <div class="index-sort-as">
      <xsl:apply-templates select="node()"/>
    </div>
  </xsl:template>
  
  <xsl:template match="*[contains(@class,'topic/title ')]">
    <xsl:choose>
      <xsl:when test="count(ancestor::*) = 1">
        <h1 class="topic-title"> <xsl:apply-templates/> </h1>
      </xsl:when>
      <xsl:when test="contains(parent::*/@class, ' topic/topic ')">
        <h2 class="topic-title"> <xsl:apply-templates/> </h2>
      </xsl:when>
      <xsl:when test="contains(parent::*/@class, ' topic/section ')">
        <h2 class="topic-title"> <xsl:apply-templates/> </h2>
      </xsl:when>
      <xsl:when test="contains(parent::*/@class, ' topic/table ')">
        <caption class="topic-title"> 
          <xsl:text>Table: </xsl:text>
          <xsl:apply-templates/> 
        </caption>
      </xsl:when>
      <xsl:otherwise>
        <div class="topic-title">
          <xsl:choose>
            <xsl:when test="contains(parent::*/@class, ' topic/fig ')">Figure: </xsl:when>
            <xsl:otherwise></xsl:otherwise>
          </xsl:choose>
          <xsl:apply-templates/>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="*[contains(@class,'topic/q ')]">
    <span class="q">&#x201C;<xsl:apply-templates/>&#x201D;</span>
  </xsl:template>

  <xsl:template match="*[contains(@class,'topic/lq ')]">
    <div class="lq">
      <div class="xopus-visualisation-blockquote">
        <span class="xopus-visualisation-opening-quote">&#x201C;</span>
        <span class="xopus-visualisation-quote">
          <xsl:apply-templates/>
        </span>
        <span class="xopus-visualisation-closing-quote">&#x201D;</span>
      </div>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class,'topic/p ')]/*[contains(@class,'topic/lq ')]">
    <span class="q">&#x201C;<xsl:apply-templates/>&#x201D;</span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/copyright ')]">
    <div class="copyright">
      <span class="xopus-visualisation-label">Copyright</span>
      <xsl:text> &#xA9; </xsl:text>
      <xsl:apply-templates select="*[contains(@class, ' topic/copyryear ')]"/>
      <xsl:text> </xsl:text>
      <xsl:apply-templates select="*[contains(@class, ' topic/copyrholder ')]"/>
    </div>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/copyryear ')]">
    <span class="copyryear">
      <xsl:value-of select="@year"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/copyrholder ')]">
    <span class="copyrholder">
      <xsl:apply-templates select="node()"/>
    </span>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/draft-comment ')]">
    <xsl:if test="$show-draft-comments = 'true'">
      <span class="draft-comment">
        <xsl:text>[ </xsl:text>
        <xsl:apply-templates select="node()"/>
        <xsl:text> ]</xsl:text>
      </span>
    </xsl:if>
  </xsl:template>
  <xsl:template match="*[contains(@class, ' topic/required-cleanup ')]">
    <xsl:if test="$show-required-cleanups = 'true'">
      <span class="required-cleanup">
        <xsl:apply-templates select="node()"/>
      </span>
    </xsl:if>
  </xsl:template>

  <xsl:template match="included-conref-content">
    <xsl:choose>
      <xsl:when test="xi:include">
        <xsl:attribute name="class">incomplete-conref</xsl:attribute>
        <xsl:apply-templates select="original-content/node()"/>
        <xsl:if test="not(original-content/node())">
          <xsl:text>&lt;</xsl:text>
          <xsl:value-of select="name(parent::*)"/>
          <xsl:text>&gt;</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="class">conref</xsl:attribute>
        <xsl:apply-templates select="*[not(self::original-content)]/node()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  
  <xsl:template match="@xml:space">
    <xsl:copy/>
  </xsl:template>
</xsl:stylesheet>
